package code.class1;

import cn.hutool.core.util.ArrayUtil;

/**
 * https://leetcode.cn/problems/remove-element/description/
 * 移除元素
 */
public class Code08_RemoveElement {
    public static void main(String[] args) {
        int[] nums = new int[]{3, 2, 2, 3};
        int target = 3;
        int ans = removeElement(nums, target);
        System.out.println(ArrayUtil.toString(nums));
        System.out.println(ArrayUtil.toString(ans));
    }

    public static int removeElement(int[] nums, int val) {
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                nums[index++] = nums[i];
            }
        }
        return index;
    }
}
